<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
       <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-circle-plus-outline"
          size="small"
          @click.stop="handlepatrol(scope.row)"
        >执行情况
        </el-button>
       </template>
    
    </avue-crud>
        <!-- 任务执行情况 -->
    <el-dialog title="任务执行情况"
                   append-to-body
                   :visible.sync="patrolBoxShow"
                   width="70%">
    <el-form ref="PatrolForm" :rules="rules" :model="patrolForm" label-width="180px" size="mini">
     <el-card shadow="hover">
        <el-table
                  :data="patrolData"
                  border
                  style="width: 100%">
                  <el-table-column
                    fixed
                    type="index"
                    label="序号"
                    min-width="10%">
                  </el-table-column>
                  <el-table-column
                    prop="taskName"
                    label="任务"
                    min-width="20%">
                  </el-table-column>
                 <el-table-column
                    prop="conditions"
                    label="执行情况"
                    min-width="30%">
                  </el-table-column>
                   <el-table-column
                    prop="userName"
                    label="执行人"
                    min-width="15%">
                  </el-table-column>
                  <el-table-column
                    prop="createTime"
                    label="执行时间"
                    min-width="15%">
                  </el-table-column>
                  <el-table-column label="状态" min-width="10%">
                    <template slot-scope="scope">
                      <el-tag v-if="scope.row.status==1" type="success" effect="dark">正常</el-tag>
                      <el-tag v-else-if="scope.row.status==2" type="danger" effect="dark">异常</el-tag>
                    </template>
                  </el-table-column>
                  <!-- <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                    <template slot-scope="scope">
                      <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                      <el-button type="text" size="small">编辑</el-button>
                    </template>
                  </el-table-column> -->
      </el-table>
     </el-card>
    </el-form>
    </el-dialog>
  </basic-container>
</template>

<script>
  import {getList,getPatrolList} from "@/api/xapply/keyplace/keyTaskCheck";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {},
        patrolForm: {},
        query: {},
        patrolBoxShow: false,
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        patrolData: [],
        option: {
          height: 'auto',
          calcHeight: 30,
          dialogWidth: 850,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          addBtn: false,
          editBtn: false,
          viewBtn: false,
          delBtn: false,
          selection: true,
          excelBtn: true,
          dialogClickModal: false,
          column: [
            {
              label: "主键id",
              prop: "id",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
             {
              label: "任务名称",
              prop: "name",
              type: "input",
              span: 24,
              rules: [{
                required: true,
                message: "请输入任务名称",
                trigger: "blur"
              }],
            },
            {
              label: "网格员",
              prop: "gridId",
              type: "select",
              span: 24,
              dicUrl: "/api/smart-user/selectGridWorker",
              props: {
                label: "title",
                value: "value"
              },
              rules: [{
                required: true,
                message: "请输入网格员",
                trigger: "blur"
              }],
            },
             {
              label: "场所",
              prop: "keyPlace",
              type: "select",
              span: 24,
              search: true,
              dicUrl: "/api/smart-xapply/keyplace/keyPlace/getList",
              props: {
                label: "title",
                value: "value"
              },
              rules: [{
                required: true,
                message: "请输入场所",
                trigger: "blur"
              }],
            },
            {
              label: "天数",
              prop: "day",
              type: "input",
              span: 24,
              hide: true,
              rules: [{
                required: true,
                message: "请输入天数",
                trigger: "blur"
              }],
            },
            {
              label: "次数",
              prop: "time",
              type: "input",
              span: 24,
              hide: true,
              rules: [{
                required: true,
                message: "请输入次数",
                trigger: "blur"
              }],
            },
           
            {
              label: "是否循环",
              prop: "sfxh",
              type: "radio",
              span: 24,
              hide: true,
              dicData: [
                  {
                    label: "循环",
                    value: "0"
                  },
                  {
                    label: "不循环",
                    value:"1"
                  }
              ],
              rules: [{
                required: true,
                message: "请输入是否循环",
                trigger: "blur"
              }],
            },
             {
              label: "频次",
              prop: "frequency",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: false,
            },
             {
              label: "进度",
              prop: "speed",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: false,
            },
             {
              label: "事件",
              prop: "event",
              type: "textarea",
              span: 24,
              overHidden: true,
              rules: [{
                required: true,
                message: "请输入事件",
                trigger: "blur"
              }],
            },
            {
              label: "已经巡查次数",
              prop: "doTime",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "任务开始时间",
              prop: "beginTime",
              type: "input",
              span: 24,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              rules: [{
                required: true,
                message: "请输入任务开始时间",
                trigger: "blur"
              }],
            },
            {
              label: "任务结束时间",
              prop: "endTime",
              type: "input",
              span: 24,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              rules: [{
                required: true,
                message: "请输入任务结束时间",
                trigger: "blur"
              }],
            },
            {
              label: "完成状态",
              prop: "finshStatus",
              type: "select",
              span: 24,
              hide: true,
              search: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              dicData: [
                  {
                    label: "未完成",
                    value: "0"
                  },
                  {
                    label: "已完成",
                    value: "1"
                  }
              ],
            },
          ]

        },
        
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
         
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      handlepatrol(row){
        console.log(row.id);
        this.patrolForm.taskId= row.id;
        this.patrolBoxShow = true;
        getPatrolList(row.id).then(res=>{
          const data = res.data.data;
          this.patrolData = data;
        });
       
      },
     
      handleCancel(FormName){
        this.patrolBoxShow = false;
        this.$refs[FormName].resetFields();
      },
      beforeOpen(done) {
        // if (["edit", "view"].includes(type)) {
        //   getDetail(this.form.id).then(res => {
        //     this.form = res.data.data;
        //   });
        // }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
